package block

import (
	"Blockchain/pow"
	"time"
)

/**
*@author:张子寒
*@QQ:1594426628
*@phone:15279093203
*@DateTime: 2022/4/12 8:51
**/
type Block struct {
	PrevHash []byte //上一个区块的hash值
	TimeStamp int64 //时间戳
	Data []byte	//交易信息
	Nonce int64//随机数
	Hash []byte	//hash值
}
func CreateBlock(data []byte,prevHash []byte)*Block{
	block:=Block{
		PrevHash:prevHash,
		TimeStamp: time.Now().Unix(),
		Data:data,
	}
	pow := pow.NewPow(block.Data, block.TimeStamp, block.PrevHash)
	hash,nonce:= pow.Run()
	block.Hash=hash
	block.Nonce=nonce
	return &block
}
